home *** CD-ROM | disk | FTP | other *** search
- function CRoundPongGame()
- {
- Mouse.addListener(this);
- this._baseDepthExplosions = 1000;
- this._scoreToWin = _root._gameOptions._scoreToWin;
- _root._gameOptions._playerOptions[1]._RGBColor = !this._isInDemoMode ? 255 : 5592416;
- _root._gameOptions._playerOptions[2]._RGBColor = !this._isInDemoMode ? 16711680 : 6313301;
- _root._gameOptions._playerOptions[3]._RGBColor = !this._isInDemoMode ? 65280 : 5595221;
- _root._gameOptions._playerOptions[4]._RGBColor = !this._isInDemoMode ? 16776960 : 6316117;
- this.quit_button._visible = !this._isInDemoMode;
- this._boundsColor = new Color(this["out of bounds line"]);
- this.InitializeGame(_root._gameOptions);
- this._ballHitSound = new Sound(this.puck1);
- this._ballHitHumpSound = new Sound(this.puck1);
- if(!this._isInDemoMode)
- {
- this._ballHitSound.attachSound("radarping.wav");
- this._ballHitHumpSound.attachSound("pipebang");
- }
- }
- function Wrap(x, min, max)
- {
- var translated = (x - min) % (max - min);
- return translated >= 0 ? min + translated : max + translated;
- }
- function WrapAngle(x)
- {
- return Wrap(x,-180,180);
- }
- function Magnitude(vec)
- {
- return Math.sqrt(vec.x * vec.x + vec.y * vec.y);
- }
- function MirrorVector(vec, angleRadians)
- {
- var vecLength = Magnitude(vec);
- var vecAngle = Math.atan2(vec.y,vec.x);
- var deltaAngle = vecAngle - angleRadians;
- var resultAngle = angleRadians - deltaAngle;
- return {x:Math.cos(resultAngle) * vecLength,y:Math.sin(resultAngle) * vecLength};
- }
- function AngleDelta(angle1, angle2)
- {
- return WrapAngle(angle1 - angle2);
- }
- CRoundPongGame.prototype = new MovieClip();
- Object.registerClass("CRoundPongGame",CRoundPongGame);
- CRoundPongGame.prototype.onMouseMove = function()
- {
- if(!this.paddle1._isAIControlled)
- {
- this.paddle1._rotationTarget = Math.atan2(this._ymouse,this._xmouse) / 3.141592653589793 * 180;
- }
- };
- CRoundPongGame.prototype.onEnterFrame = function()
- {
- this._nFrames = this._nFrames + 1;
- if(!this.paddle1._isAIControlled)
- {
- this.paddle1._rotation += !Key.isDown(39) ? 0 : - this._playerPaddleSpeed;
- this.paddle1._rotation += !Key.isDown(37) ? 0 : this._playerPaddleSpeed;
- }
- if(this._cFramesSinceLastExplosion % 40 < 1)
- {
- this.CreateHumpExplosion();
- }
- this._cFramesSinceLastExplosion = this._cFramesSinceLastExplosion + 1;
- };
- CRoundPongGame.prototype.InitializeGame = function(gameOptions)
- {
- this._cFramesSinceLastExplosion = 0;
- this._oldXMouse = this._xmouse;
- this.attachMovie("CPuck","puck1",10);
- this._paddleHitAcceleration = _root._gameOptions._paddleHitAcceleration;
- this._initialPuckSpeed = _root._gameOptions._initialPuckSpeed;
- this._nPaddles = gameOptions._nPlayers;
- var i;
- i = 1;
- while(i <= this._nPaddles)
- {
- this.attachMovie("CPaddle","paddle" + i,i,{_rotation:- i * (270 / (this._nPaddles - 1)),_arcLength:20,_isAIControlled:gameOptions._playerOptions[i]._isAIControlled,_maxRotationSpeed:(!gameOptions._playerOptions[i]._isExpert ? (!gameOptions._playerOptions[i]._isAIControlled ? 20 : 12) : (!gameOptions._playerOptions[i]._isAIControlled ? 10 : 7))});
- var paddle = this["paddle" + i];
- paddle._color = new Color(paddle);
- paddle._color.setRGB(gameOptions._playerOptions[i]._RGBColor);
- var scoreRotation = -135 + 90 * (i - 1);
- if(this._nPaddles > 3)
- {
- var baseRotation = i >= 3 ? 45 : -135;
- var offsetRotation = !(i & 1) ? -20 : 20;
- scoreRotation = baseRotation + offsetRotation;
- }
- this.attachMovie("CScoreBoard","CScoreBoard" + i,10000 + i,{_rotation:scoreRotation});
- this["CScoreBoard" + i].playerScore.textColor = gameOptions._playerOptions[i]._RGBColor;
- i++;
- }
- this._ndxServingPlayer = 1;
- this._ndxReceivingPlayer = this.WrapPlayerIndex(this._ndxServingPlayer + 1);
- this.GetReceivingPlayer().BeginReceiving();
- if(Math.random() < 0.5)
- {
- this.SwapServerAndReceiver();
- }
- this._boundsColor.setRGB(this.GetReceivingPlayer()._color.getRGB());
- this.EnableRandomBackground();
- clearInterval(_root._intervalID);
- _root._intervalID = setInterval(this,"Serve",800);
- };
- CRoundPongGame.prototype.ShutdownGame = function()
- {
- clearInterval(_root._intervalID);
- this.removeMovieClip("puck1");
- var i;
- i = 1;
- while(i <= this._nPaddles)
- {
- this.removeMoveClip("paddle" + i);
- i++;
- }
- };
- CRoundPongGame.prototype.BallHit = function()
- {
- this._ballHitSound.start();
- this.SwapServerAndReceiver();
- if(this._nPaddles == 1)
- {
- this.paddle1.Score();
- this.CScoreBoard1.playerScore.text = this.paddle1._score;
- }
- this._lengthVolley = this._lengthVolley + 1;
- if(this._lengthVolley % 5 < 1)
- {
- this.puck1._velX *= this._paddleHitAcceleration;
- this.puck1._velY *= this._paddleHitAcceleration;
- }
- };
- CRoundPongGame.prototype.BallHitHump = function()
- {
- this._ballHitHumpSound.start();
- };
- CRoundPongGame.prototype.SwapServerAndReceiver = function()
- {
- this.GetReceivingPlayer().FinishedReceiving();
- this._ndxServingPlayer = this.WrapPlayerIndex(++this._ndxServingPlayer);
- this._ndxReceivingPlayer = this.WrapPlayerIndex(this._ndxServingPlayer + 1);
- this.GetReceivingPlayer().BeginReceiving();
- this._boundsColor.setRGB(this.GetReceivingPlayer()._color.getRGB());
- this.CreateHumpExplosion();
- };
- CRoundPongGame.prototype.PuckOutOfBounds = function()
- {
- if(this._nPaddles > 1)
- {
- this.GetServingPlayer().Score();
- if(this._nPaddles > 2)
- {
- this.GetReceivingPlayer().ScoreFailure();
- }
- }
- else
- {
- this.paddle1._score = 0;
- }
- this.puck1.GoIdle(true);
- if(this._scoreToWin > 0 && this.GetServingPlayer()._score >= this._scoreToWin)
- {
- var i;
- i = 1;
- while(i <= this._nPaddles)
- {
- this["CScoreBoard" + i].playerScore.text = this["paddle" + i]._score;
- i++;
- }
- _root.gotoAndPlay("victory announcement");
- }
- else
- {
- clearInterval(_root._intervalID);
- _root._intervalID = setInterval(this,"Serve",800);
- }
- };
- CRoundPongGame.prototype.GetServingPlayer = function()
- {
- return this["paddle" + this._ndxServingPlayer];
- };
- CRoundPongGame.prototype.GetReceivingPlayer = function()
- {
- return this["paddle" + this._ndxReceivingPlayer];
- };
- CRoundPongGame.prototype.Serve = function()
- {
- clearInterval(_root._intervalID);
- var i;
- i = 1;
- while(i <= this._nPaddles)
- {
- this["CScoreBoard" + i].playerScore.text = this["paddle" + i]._score;
- i++;
- }
- this.puck1.GoIdle(false);
- var launchAngle = Math.random() * 3.141592653589793 * 2;
- this.puck1._velX = Math.cos(launchAngle) * this._initialPuckSpeed;
- this.puck1._velY = Math.sin(launchAngle) * this._initialPuckSpeed;
- this.puck1._x = this.puck1._velX / this._initialPuckSpeed * -60;
- this.puck1._y = this.puck1._velY / this._initialPuckSpeed * -60;
- this._lengthVolley = 1;
- };
- CRoundPongGame.prototype.EnableRandomBackground = function()
- {
- var choice = Math.random();
- this.background1._visible = false;
- this.background2._visible = false;
- this.background3._visible = false;
- if(choice < 0.33)
- {
- this.background1._visible = true;
- }
- else if(choice < 0.66)
- {
- this.background2._visible = true;
- }
- else
- {
- this.background3._visible = true;
- }
- };
- CRoundPongGame.prototype.WrapPlayerIndex = function(x)
- {
- return Wrap(x,1,this._nPaddles + 1);
- };
- CRoundPongGame.prototype.CreateHumpExplosion = function()
- {
- if(this._nActiveHumpExplosions < 2)
- {
- this._cFramesSinceLastExplosion = 0;
- this.attachMovie("CHumpExplosion","CHumpExplosion" + ++this._nHumpExplosions,this._baseDepthExplosions + this._nHumpExplosions,{_x:-100,_y:100,_hue:this.GetReceivingPlayer()._color.getRGB(),_alpha:40});
- }
- };
-